package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.UserInfo;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Map;

@RestController
@RequestMapping("admin/auth")
public class AuthController {

    @PostMapping("login")
    public BaseRespVo login(@RequestBody Map map) {
        String username = (String) map.get("username");
        String password = (String) map.get("password");
        //登录的具体业务 → shiro整合的时候
        return BaseRespVo.ok("8d83d363-d08c-4ceb-8794-82d31fcff583");
    }
    @RequestMapping("info")
    public BaseRespVo info(String token){

        //shiro在做 → 获得user信息
        int userId = 1;
        //根据userId查询对应的信息
        UserInfo userInfo = new UserInfo();
        userInfo.setAvatar("https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
        userInfo.setName("admin123");
        ArrayList<String> perms = new ArrayList<>();
        perms.add("*");//全部权限 → 不同的管理员perms里的数据不同
        userInfo.setPerms(perms);

        ArrayList<String> roles = new ArrayList<>();
        userInfo.setRoles(roles);
        roles.add("超级管理员");

        return BaseRespVo.ok(userInfo);
    }

}
